package com.basemapper;


import com.miaoxun.dao.provider.BaseProvider;
import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Map;

public interface BasicMapper<T> {

    /**
     * @param key
     * @param clazzName
     * @return
     */
    @SelectProvider(type = BaseProvider.class, method = "getModelById")
    T getModelById(Object key, String clazzName);

    /**
     * @param clazzName
     * @return
     */
    @SelectProvider(type = BaseProvider.class, method = "getAll")
    List<T> getAll(String clazzName);

    /**
     * 更新
     *
     * @param obj
     * @return
     */
    @InsertProvider(type = BaseProvider.class, method = "update")
    int update(Object obj);

    /**
     * 添加 主键返回到backid
     *
     * @param entity
     * @return
     */
    @InsertProvider(type = BaseProvider.class, method = "insert")
    @Options(useGeneratedKeys = true, keyProperty = "backId")
    int insert(Object entity);

    /**
     * 对象删除
     *
     * @param entity
     * @return
     */
    @DeleteProvider(type = BaseProvider.class, method = "delete")
    int delete(Object entity);

    /**
     * 主键删除
     *
     * @param key
     * @param clazzName
     * @return
     */
    @DeleteProvider(type = BaseProvider.class, method = "deleteById")
    int deleteById(Object key, String clazzName);


    /********************************************************************************/
    /**                                                                             */
    /** <div>一般方法</div>                                                         */
    /**                                                                              */
    /*********************************************************************************/

    /**
     * list
     *
     * @param map
     * @param clazzName
     * @return
     */
    @SelectProvider(type = BaseProvider.class, method = "getModelList")
    List<T> getModelList(Map<String, String> map, String clazzName);

    /**
     * @param map
     * @param clazzName
     * @param filed
     * @return
     */
    @SelectProvider(type = BaseProvider.class, method = "max")
    Object max(Map<String, String> map, String clazzName, String filed);


    /**
     * 批量删除
     *
     * @param ids
     * @param clazzName
     * @return
     */
    @DeleteProvider(type = BaseProvider.class, method = "batchRemove")
    int batchRemove(Object[] ids, String clazzName);


}